package com.m3958.firstgwt.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.m3958.gwtutil.clientside.client.jso.AssetJso;
import com.smartgwt.client.types.AnimationEffect;
import com.smartgwt.client.widgets.Window;

@Singleton
public class AssetsDialog extends Composite {

	private static AssetsDialogUiBinder uiBinder = GWT
			.create(AssetsDialogUiBinder.class);

	interface AssetsDialogUiBinder extends UiBinder<Widget, AssetsDialog> {
	}
	
	@Inject @UiField(provided=true)
	AttachmentsManager am;
	
	private Window aw;
	
	private boolean initialized = false;
	
	public AssetsDialog initMe(){
		if(!initialized){
			initialized = true;
			am.initMe().setHeight("350px");
			initWidget(uiBinder.createAndBindUi(this));
			aw = new Window();
			aw.setTitle("附件管理");
			aw.setCanDragReposition(true);  
	        aw.setCanDragResize(true);
	        aw.setWidth100();
	        aw.setHeight(380);
	        FlowPanel vp = new FlowPanel();
	        vp.setHeight("500px");
	        vp.setWidth("100%");
	        vp.add(this.am);
//	        VLayout vl = new VLayout(10);
//	        vl.setWidth100();
//	        vl.setHeight(400);//vlayout必须设定高度，不然内部的gwt组件不会自动扩展。
//	        vl.addMember(am);
//	        this.am.setContainerLayout(vl);
//			aw.addItem(vl);
	        aw.addItem(vp);
			aw.setAnimateShowEffect(AnimationEffect.WIPE);
		}
		return this;
	}
	
	public void show(){
		aw.show();
		am.resetMyatCellTable();
		am.switchToMyAtCellTable(false);
		aw.redraw();
	}
	
	public void hide(){
		aw.hide();
	}
	

	public void setAttach(JsArray<AssetJso> attachmentsList) {
		am.setAttach(attachmentsList);
	}

	public String getAttachStr() {
		return am.getAttachStr();
	}
}
